home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_oth / ifp / ifp.txt < prev   
Text File  |  1987-02-07  |  31KB  |  1,057 lines

  1.                           IFP Reference                         1
  2.  
  3. _1.  _B_u_i_l_t-_i_n _F_u_n_c_t_i_o_n_s
  4.  
  5.  
  6.      This section is a reference guide to the built-in  functions
  7.  
  8. in IFP. The following sets (types) are used in the definitions of
  9.  
  10. functions:
  11.  
  12.  
  13.          A    atoms
  14.          B    boolean values
  15.          O    objects
  16.          R    real numbers
  17.          Z    integers
  18.          S    strings
  19.          T*   sequences with element type T
  20.          T+   non-empty sequences with element type T
  21.          Tn   sequences of length n with element type T
  22.  
  23.  
  24. A function returns ``?'' if the argument is not  in  its  domain.
  25.  
  26. The notation xn denotes the nth element of a sequence X.
  27.  
  28.  
  29.      For example, the domain of the addition function is [X,Y] in
  30.  
  31. [R,R].   That  is  addition  takes  a pair of real numbers as its
  32.  
  33. argument.  We could also write this as [X,Y] in R2, since a  pair
  34.  
  35. is a sequence of length two.
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.                         December 5, 1985
  67.                           IFP Reference                         2
  68.  
  69. _1._1.  _S_t_r_u_c_t_u_r_a_l _F_u_n_c_t_i_o_n_s (/_s_y_s)
  70.  
  71.  
  72.      Structural functions are assemble,  reorganize,  and  select
  73.  
  74. data.  The primitive structural functions are listed below:
  75.  
  76.  
  77. ______________________________________________________________________
  78. _|N_a_m_e_______D_o_m_a_i_n__________________D_e_f_i_n_i_t_i_o_n___________________________|
  79. |                                                                    |
  80. |apndl     [X,Y] in [O,On]        <X, y1 , y2 , ...yn>               |
  81. |                                                                    |
  82. |apndr     [X,Y] in [Om,O]        <x1, x2, ... xm, Y>                |
  83. |                                                                    |
  84. |cat       X in O**               catenate sequences                 |
  85. |                                                                    |
  86. |distl     [X,Y] in [O,On]        <<X,y1> <X,y2> ... <X,yn>>         |
  87. |                                                                    |
  88. |distr     [X,Y] in [Om,O]        <<x1,Y> <x2,Y> ... <xm,Y>>         |
  89. |                                                                    |
  90. |dropl     [X,K] in [On, 0<_Z<_n]   drop K elements from left end of X |
  91. |                                                                    |
  92. |dropr     [X,K] in [On, 0<_Z<_n]   drop K elements from right end of X|
  93. |                                                                    |
  94. |iota      n in Z>_0               <1,2,...n>                         |
  95. |                                                                    |
  96. |length    X in On                number of elements in X            |
  97. |                                                                    |
  98. |pick      [X,K] in [On, 0<Z<_n]   Kth element of X                   |
  99. |                                                                    |
  100. |repeat    [X,K] in [O,0<_Z]       sequence <X,X...X> of length K     |
  101. |                                                                    |
  102. |reverse   X in On                reversal of X                      |
  103. |                                                                    |
  104. |takel     [X,K] in [On, 0<_Z<_n]   take K elements from left end of X |
  105. |                                                                    |
  106. |taker     [X,K] in [On, 0<_Z<_n]   take K elements from right end of X|
  107. |                                                                    |
  108. |tl        X in O+                (tail) drop first element of X     |
  109. |                                                                    |
  110. |tlr       X in O+                (right tail) drop last element of X|
  111. |                                                                    |
  112. |trans     X is matrix            transpose X                        |
  113. _|_____________________________________________________________________|
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.                         December 5, 1985
  133.                           IFP Reference                         3
  134.  
  135. _1._2.  _A_r_i_t_h_m_e_t_i_c (/_m_a_t_h/_a_r_i_t_h)
  136.  
  137.  
  138.      Most IFP arithmetic functions are found here.   Below  is  a
  139.  
  140. table  of  the existing functions.  Some function's domain may be
  141.  
  142. further restricted due to range limitations.
  143.  
  144.  
  145.       ____________________________________________________
  146.      |_N_a_m_e______D_o_m_a_i_n______________D_e_f_i_n_i_t_i_o_n______________|
  147.      |                                                   |
  148.      | +        [X,Y] in [R,R]     X+Y                   |
  149.      |                                                   |
  150.      | -        ...                X-Y                   |
  151.      |                                                   |
  152.      | *        ...                XxY                   |
  153.      |                                                   |
  154.      | %        [X,Y] in [R,R=/0]   X/Y                   |
  155.      |                                                   |
  156.      | add1     X in R             X+1                   |
  157.      |                                                   |
  158.      | arcsin   X in R, -1<_X<_1     arcsine X             |
  159.      |                                                   |
  160.      | arccos   X in R, -1<_X<_1     arccosine X           |
  161.      |                                                   |
  162.      | arctan   X in R             arctangent  X         |
  163.      |                                                   |
  164.      | cos      X in R             cosine X              |
  165.      |                                                   |
  166.      | div      [X,Y] in [R,R=/0]   floor (X/Y)           |
  167.      |                                                   |
  168.      | exp      X in R             e to the Xth power    |
  169.      |                                                   |
  170.      | ln       X in R>0           natural logarithm of X|
  171.      |                                                   |
  172.      | max      [X,Y] in [R,R]     maximum of X and Y    |
  173.      |                                                   |
  174.      | min      [X,Y] in [R,R]     minimum of X and Y    |
  175.      |                                                   |
  176.      | minus    X in R             -X                    |
  177.      |                                                   |
  178.      | mod      [X,Y] in [R,R]     X modulo Y            |
  179.      |                                                   |
  180.      | power    [X,Y] in [R>_0,R]   X to Yth power        |
  181.      |                                                   |
  182.      | sin      X in R             sine X                |
  183.      |                                                   |
  184.      | sqrt     X in R>0           square root of X      |
  185.      |                                                   |
  186.      | sub1     X in R             X-1                   |
  187.      |                                                   |
  188.      | sum      X in R*            summation of X        |
  189.      |                                                   |
  190.      | tan      X in R             tangent of X          |
  191.      |____________________________________________________|
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.                         December 5, 1985
  199.                           IFP Reference                         4
  200.  
  201. _1._3.  _L_o_g_i_c (/_m_a_t_h/_l_o_g_i_c)
  202.  
  203.  
  204.      Most IFP primitive functions returning  boolean  values  are
  205.  
  206. found here.  Below is a table of the existing functions:
  207.  
  208.  
  209. ______________________________________________________________________
  210. _|N_a_m_e_______D_o_m_a_i_n____________________D_e_f_i_n_i_t_i_o_n_________________________|
  211. |                                                                    |
  212. |=         [X,Y] in [O,O]           X=Y                              |
  213. |                                                                    |
  214. |~=        ...                      X=/Y                              |
  215. |                                                                    |
  216. |<         [X,Y] in [R,R] u [S,S]   X<Y                              |
  217. |                                                                    |
  218. |<=        ...                      X<_Y                              |
  219. |                                                                    |
  220. |>=        ...                      X>_Y                              |
  221. |                                                                    |
  222. |>         ...                      X>Y                              |
  223. |                                                                    |
  224. |~         X in B                   not X                            |
  225. |                                                                    |
  226. |and       [X,Y] in [B,B]           X AND Y                          |
  227. |                                                                    |
  228. |all       X in B*                  all elements of X are true       |
  229. |                                                                    |
  230. |any       X in B*                  at least one element of X is true|
  231. |                                                                    |
  232. |atom      X in O                   X is an atom                     |
  233. |                                                                    |
  234. |boolean   X in O                   X is boolean                     |
  235. |                                                                    |
  236. |false     X in O                   X is #f                          |
  237. |                                                                    |
  238. |imply     [X,Y] in [B,B]           ~X OR Y                          |
  239. |                                                                    |
  240. |longer    [X,Y] in [Om,On]         m>n                              |
  241. |                                                                    |
  242. |member    [X,Y] in [O*,O]          Y is an element of X             |
  243. |                                                                    |
  244. |numeric   X in O                   X is a number                    |
  245. |                                                                    |
  246. |null      X in O*                  X = <>                           |
  247. |                                                                    |
  248. |odd       X in Z                   X is odd                         |
  249. |                                                                    |
  250. |or        [X,Y] in [B,B]           X OR Y                           |
  251. |                                                                    |
  252. |pair      X in O                   X is a pair                      |
  253. |                                                                    |
  254. |shorter   [X,Y] in [Om, On]        m<n                              |
  255. |                                                                    |
  256. |xor       [X,Y] in [B,B]           X=/Y                              |
  257. _|_____________________________________________________________________|
  258.  
  259.  
  260. String inequalities are defined from the lexigraphical  (diction-
  261.  
  262. ary) ordering.
  263.  
  264.                         December 5, 1985
  265.                           IFP Reference                         5
  266.  
  267. _1._4.  _S_t_r_i_n_g _F_u_n_c_t_i_o_n_s (/_s_y_s)
  268.  
  269.  
  270.      The string functions are:
  271.  
  272.  
  273.   ____________________________________________________________
  274.  |_N_a_m_e_______D_o_m_a_i_n_____D_e_f_i_n_i_t_i_o_n______________________________|
  275.  |                                                           |
  276.  | explode   X in S    sequence of characters in X           |
  277.  |                                                           |
  278.  | implode   X in S*   string made by catenating strings in X|
  279.  |                                                           |
  280.  | patom     X in A    string representation of X            |
  281.  |____________________________________________________________|
  282.  
  283.  
  284.  
  285. _1._5.  _M_i_s_c_e_l_l_a_n_e_o_u_s _F_u_n_c_t_i_o_n_s (/_s_y_s)
  286.  
  287.  
  288.      The miscellaneous functions are listed below.  Each function
  289.  
  290. description is preceded by a title line of the form:
  291.  
  292. function                     domain                    definition
  293.  
  294.  
  295. _________________________________________________________________
  296.  
  297.  
  298. apply                    [X,F] in [O,S*]             apply F to X
  299.  
  300.  
  301.     F is a sequence of strings representing a path to  a  de-
  302.     fined function.  The result is the function referenced by
  303.     F applied to X.  Example:
  304.  
  305.                 <<3 4> <math arith "+">> : apply -> 7
  306.  
  307.  
  308.  
  309. _________________________________________________________________
  310.  
  311.  
  312. assoc                  [X,Y] in [(O+)*,O]      associative lookup
  313.  
  314.  
  315.     X is an association sequence,  which  is  a  sequence  of
  316.     non-empty subsequences.  The first element of each subse-
  317.     quence is the _k_e_y of the subsequence.  The result of  as-
  318.     soc  is the first subsequence of X with a key equal to Y.
  319.     If no matching key is found, f is returned.  The key  may
  320.     be any type of object.  Examples:
  321.  
  322.              <<<a b c> <w x y z> <i j>> w> -> <w x y z>
  323.              <<<a b c> <w x y z> <i j>> U> -> f
  324.  
  325.  
  326.  
  327. _________________________________________________________________
  328.  
  329.  
  330.                         December 5, 1985
  331.                           IFP Reference                         6
  332.  
  333. def                         X in S+                    definition
  334.  
  335.  
  336.     The definition function returns the object representation
  337.     of  its  argument.  The representation of a function is a
  338.     sequence of strings  denoting  its  absolute  path.   The
  339.     representation of a PFO is a sequence.  The first element
  340.     of the sequence is a path to the PFO.  The remaining ele-
  341.     ments  of  the  sequence are parameters of the functional
  342.     form.  Suppose, for example, we define the inner  product
  343.     function:
  344.  
  345.            DEF Inner AS trans | EACH * END | INSERT + END
  346.  
  347.     and  ``Inner''  is  defined   with   a   module   with   path
  348.     ``/math/linear''.   Then  ``<math  linear Inner> : def'' will
  349.     result in:
  350.  
  351.                  <
  352.                       <sys compose>
  353.                       <sys trans>
  354.                       <<sys each> <math arith *>>
  355.                       <<sys insertr> <math arith +>>
  356.                  >
  357.  
  358.     Currently, the representations of PFO are:
  359.  
  360.     #c                       <<sys constant> #c>
  361.     #?                       <<sys constant>>
  362.     n                        <<sys selectl> n>
  363.     nr                       <<sys selectr> n>
  364.     f1 | f2 | ... fn         <<sys compose>, f1 , f2 , ... fn>
  365.     [f1 , f2 , ... fn ]      <<sys construct>, f1 , f2 , ... fn>
  366.     ^c                       <<sys fetch> c>
  367.     EACH f END               <<sys each> f>
  368.     FILTER p END             <<sys filter> p>
  369.     INSERT f END             <<sys insertr> f>
  370.     IF p THEN g ELSE h END   <<sys if> p g h>
  371.     WHILE p DO f END         <<sys while> p f>
  372.  
  373.     ELSIF clauses are always expanded into equivalent nested  IF-
  374.     THEN-ELSE  constructions.   Note the special case for #?, the
  375.     representation <<sys constant> ?> would be useless due to the
  376.     bottom-preserving property.
  377.  
  378.  
  379. _________________________________________________________________
  380.  
  381.  
  382. id                           X in O                      identity
  383.  
  384.  
  385.     The identity function returns its argument.  It is useful
  386.     as  a  place  holder in PFO.  For example, the ``square''
  387.     function can be written as:
  388.  
  389.  
  390.             DEF Square AS [id,id] | *;
  391.  
  392.  
  393.  
  394.  
  395.  
  396.                         December 5, 1985
  397.                           IFP Reference                         7
  398.  
  399. _2.  _P_r_o_g_r_a_m _F_o_r_m_i_n_g _O_p_e_r_a_t_i_o_n_s
  400.  
  401.  
  402.      Program forming operations combine functions and objects  to
  403.  
  404. create new functions.
  405.  
  406.  
  407. _2._1.  _C_o_n_s_t_a_n_t
  408.  
  409.  
  410.      Constant  functions  always  return  the  same  result  when
  411.  
  412. applied  to any value which is not ``?''.  Constant functions are
  413.  
  414. written as:
  415.  
  416.  
  417.         #c
  418.  
  419.  
  420. where c is the constant value to be returned. A constant function
  421.  
  422. applied to ``?'' results in ``?''.  Note that the function ``#?''
  423.  
  424. always returns `?'.  Examples:
  425.  
  426.  
  427.                923 : #<cat in hat> -> <cat in hat>
  428.                <a b c d e f> : #427 -> 427
  429.                ? : #<q w er t y> -> ?
  430.                5 : #? -> ?
  431.  
  432.  
  433.  
  434. _2._2.  _S_e_l_e_c_t_i_o_n
  435.  
  436.  
  437.      Selector functions return the nth element of a sequence  and
  438.  
  439. are  written  as n, where n is a positive integer.  Note the dis-
  440.  
  441. tinction between #5, which returns the  value  5,  and  5,  which
  442.  
  443. returns  the  fifth  element  of  its  argument. There are also a
  444.  
  445. corresponding set of select-from-right functions, written as  nr.
  446.  
  447. These  select  the  nth  element of a sequence, counting from the
  448.  
  449. right. All selectors return ``?'' if the argument has no nth ele-
  450.  
  451. ment  or  is not a sequence.  Below are some examples of applying
  452.  
  453. selector functions:
  454.  
  455.  
  456.               <a b c d e> : 1 -> a
  457.               <a b c d e> : 2 -> b
  458.               <apple banana cherry> : 1r -> cherry
  459.               <apple banana cherry> : 4 -> ?
  460.  
  461.  
  462.                         December 5, 1985
  463.                           IFP Reference                         8
  464.  
  465.               hello : 1 -> ?
  466.  
  467.  
  468.  
  469. _2._3.  _C_o_m_p_o_s_i_t_i_o_n
  470.  
  471.  
  472.      The function composition of two functions is written as:
  473.  
  474.  
  475.                               f | g
  476.  
  477. Applying the result function is the same as applying f  and  then
  478.  
  479. g.  E.g.: Function composition is defined by the equality:
  480.  
  481.  
  482.                     x : (f | g) =_ (x : f) : g
  483.  
  484. Since function composition is  associative,  the  composition  of
  485.  
  486. more than two functions does not require parentheses.  The compo-
  487.  
  488. sition of f1,f2,...fn is written:
  489.  
  490.  
  491.                          f1 | f2 | ...fn
  492.  
  493. Composition syntax is identical to UNIX's  pipe  notation  for  a
  494.  
  495. reason:  function  composition  is  isomorphic  to a pipe between
  496.  
  497. processes without side effects.
  498.  
  499.  
  500. _2._4.  _C_o_n_s_t_r_u_c_t_i_o_n
  501.  
  502.  
  503.      The construction of functions is written as  bracketed  list
  504.  
  505. of  the functions.  For example, the construction of functions fi
  506.  
  507. is written:
  508.  
  509.  
  510.                           [f1,f2,...fn]
  511.  
  512. Function construction is defined by the equality:
  513.  
  514.  
  515.              x : [f1,f2,...fn] =_ <x:f1,x:f2,...x:fn>
  516.  
  517.  
  518. _2._5.  _A_p_p_l_y _t_o _E_a_c_h
  519.  
  520.  
  521.      The EACH functional form applys a function to  each  element
  522.  
  523. of a sequence.  It is written as
  524.  
  525.  
  526.  
  527.  
  528.                         December 5, 1985
  529.                           IFP Reference                         9
  530.  
  531.  
  532.         EACH f END
  533.  
  534.  
  535. It is defined by the equality:
  536.  
  537.  
  538.         <x1,x2,...xn> : EACH f END =_ <x1:f,x2:f,...xn:f>
  539.  
  540.  
  541.  
  542. _2._6.  _I_f-_T_h_e_n-_E_l_s_e
  543.  
  544.  
  545.      The IF functional form allows conditional function  applica-
  546.  
  547. tion.  It is written as
  548.  
  549.  
  550.         IF p THEN g ELSE h END
  551.  
  552.  
  553. and is defined by the equality:
  554.  
  555.  
  556.                                      | x:g  if p=#t
  557.                                      |
  558.         x : IF p THEN g ELSE h END =_ | x:h  if p=#f
  559.                                      | ?   otherwise
  560.                                      |
  561.  
  562. The level of nesting of conditional forms may be reduced by using
  563.  
  564. ELSIF clauses:
  565.  
  566.  
  567.         IF p1 THEN f1 ELSIF p2 THEN f2 ELSIF ... ELSE g END
  568.  
  569.  
  570.  
  571. _2._7.  _F_i_l_t_e_r
  572.  
  573.  
  574.      The FILTER functional form filters  through  elements  of  a
  575.  
  576. sequence satisfying a predicate.  It is written as:
  577.  
  578.  
  579.         FILTER p END
  580.  
  581.  
  582. where p is the predicate.  It is defined by the functional equal-
  583.  
  584. ity:
  585.  
  586.  
  587.         FILTER p END =_ EACH IF p THEN [id] ELSE [ ] END END | cat
  588.  
  589.  
  590. For example, if you wish  to  find  all  numeric  elements  in  a
  591.  
  592. sequence, you could write:
  593.  
  594.                         December 5, 1985
  595.                           IFP Reference                        10
  596.  
  597.  
  598.         FILTER numeric END
  599.  
  600.  
  601. The FILTER functional form is an IFP extension to Backus' FP.
  602.  
  603.  
  604. _2._8.  _R_i_g_h_t _I_n_s_e_r_t
  605.  
  606.  
  607.      The INSERT functional form is defined by the recursion:
  608.  
  609.  
  610.         INSERT f END =_ IF tl|null THEN 1 ELSE [1,tl | INSERT f END] | f END
  611.  
  612.  
  613. Typically it is used for crunching a sequence down.  For example,
  614.  
  615.  
  616.         INSERT + END
  617.  
  618.  
  619. returns the sum of a sequence.
  620.  
  621.  
  622.      Unlike Backus' FP, functions formed with INSERT  are  always
  623.  
  624. undefined  for empty sequences.  The reason is that it is imprac-
  625.  
  626. tical for the interpreter to know the identity element  of  user-
  627.  
  628. defined  functions.   The  number  of cases where the interpreter
  629.  
  630. could know the identity element are so few that you might as well
  631.  
  632. define special functions for those cases, e.g:
  633.  
  634.  
  635.         DEF sum AS IF null THEN #0 ELSE INSERT + END END;
  636.  
  637.  
  638. Alternatively, you can append the identity element to the end  of
  639.  
  640. the sequence before inserting, e.g.:
  641.  
  642.  
  643.         DEF sum AS [id,#0] | apndr | INSERT + END;
  644.  
  645.  
  646.  
  647.      Currently there is  no  ``left  insert''  form.d   The  left
  648.  
  649. insertion of f can be written as:
  650.  
  651.  
  652.         reverse | INSERT reverse|f END
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.                         December 5, 1985
  661.                           IFP Reference                        11
  662.  
  663. _2._9.  _W_h_i_l_e
  664.  
  665.  
  666.      The WHILE functional form allows indefinite composition.  It
  667.  
  668. is written as:
  669.  
  670.  
  671.         WHILE p DO f END;
  672.  
  673.  
  674. and is defined by the recursive functional equality:
  675.  
  676.  
  677.         WHILE p DO f END =_ IF p THEN f | WHILE p DO f END ELSE id END
  678.  
  679.  
  680.  
  681. _2._1_0.  _F_e_t_c_h
  682.  
  683.  
  684.      The fetch functional form allows easy access to  association
  685.  
  686. sequences  (see function /sys/assoc for a description of associa-
  687.  
  688. tion sequences.)  A fetch is written as ^c, where c is an object.
  689.  
  690. The fetch form is defined by the functional equality:
  691.  
  692.  
  693.         ^c =_ IF EACH pair END | all THEN [id,#c]|assoc|2
  694.              ELSE #?
  695.              END;
  696.  
  697.  
  698. Note that the input is restricted to a sequence of pairs.
  699.  
  700.  
  701. _3.  _C_o_m_m_e_n_t_s
  702.  
  703.  
  704.      Comments are delimited  by  matching  pairs  of  ``(*''  and
  705.  
  706. ``*)''.   Comments  may  be  inserted  anywhere not adjacent to a
  707.  
  708. token.  For example:
  709.  
  710.  
  711.         DEF foo AS bar; (* This is a comment.  DEF foo AS bar is not a comment *)
  712.  
  713.  
  714.  
  715. _4.  _S_y_n_t_a_x _S_u_m_m_a_r_y
  716.  
  717.  
  718.      Below is an EBNF grammar for IFP:
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.                         December 5, 1985
  727.                           IFP Reference                        12
  728.  
  729. ____________________________________________________________________________
  730. |Def ->            'DEF String 'AS' Comp ';'                               |
  731. |Comp ->            Simple { '|' Simple }                                  |
  732. |Simple ->          Conditional | Constant | Construction | Each | Filter ||
  733. |                  Insert  | Path | While | Fetch | Debug                  |
  734. |Conditional ->    'IF' Comp 'THEN' Comp { 'ELSIF' Comp 'THEN' Comp }      |
  735. |                  'ELSE' Comp 'END'                                       |
  736. |While ->          'WHILE' Comp 'DO' Comp 'end'                            |
  737. |Insert ->         'INSERT' Comp 'END'                                     |
  738. |Each ->           'EACH' Comp 'END'                                       |
  739. |Filter ->         'FILTER' Comp 'END'                                     |
  740. |Fetch ->          '^' String                                              |
  741. |Constant ->       '#' Object                                              |
  742. |Debug ->          '@' Object                                              |
  743. |Construction ->   '[' [Comp {',' Comp}] ']'                               |
  744. |Path ->           ['/'] String {'/' String}                               |
  745. |Object ->         Bottom | Atom | '<' [Atom {','Atom}] '>'                |
  746. |Bottom ->         '?'                                                     |
  747. |Atom ->           Number | String | Boolean                               |
  748. _||B_o_o_l_e_a_n__-_>_________'_t_'__|__'_f_'_________________________________________________||
  749.  
  750.  
  751. Strings may be in single or double quotes.  The strings ``t'' and
  752.  
  753. ``f''  must  be  quoted  to  distinguish them from boolean atoms.
  754.  
  755. Strings of digits must also be quoted to  distinguish  them  from
  756.  
  757. numeric atoms.
  758.  
  759.  
  760. _5.  _R_u_n_n_i_n_g _I_F_P _w_i_t_h _M_S-_D_O_S
  761.  
  762.  
  763. _5._1.  _P_r_e_r_e_q_u_i_s_i_t_e _H_a_r_d_w_a_r_e
  764.  
  765.  
  766.      The MS-DOS version needs at  least  a  256K  system.   Extra
  767.  
  768. memory for a RAM-disk is convenient but not necessary.
  769.  
  770.  
  771. _5._2.  _P_r_e_r_e_q_u_i_s_i_t_e _S_o_f_t_w_a_r_e
  772.  
  773.  
  774.      There are three programs you will need: the IFP  interpreter
  775.  
  776. (IFP.EXE),  a text editor, and a directory lister.  You must sup-
  777.  
  778. ply the text editor and directory lister.  (The ``PC-Write'' edi-
  779.  
  780. tor  works  with  IFP under DOS 2.0 and 3.0; ``edlin'' only works
  781.  
  782. under DOS 3.0; I haven't tried any others).  All three  of  these
  783.  
  784. programs  must  reside  on  a  different disk drive than your IFP
  785.  
  786. functions.  If you have enough memory, it is advantageous to  put
  787.  
  788. these  on a RAM-disk.  The IFP function files should be kept on a
  789.  
  790. floppy or hard disk, just in case your machine crashes.
  791.  
  792.                         December 5, 1985
  793.                           IFP Reference                        13
  794.  
  795. _5._3.  _R_u_n_n_i_n_g _I_F_P
  796.  
  797.  
  798.      Before invoking IFP, two  environment  variables  should  be
  799.  
  800. set.  The  ``EDITOR''  variable should be set to the name of your
  801.  
  802. favorite  editor.   The  default  editor  is  ``c:ed.exe''.   The
  803.  
  804. ``FPDIR''  variable  should  be  set to the name of your favorite
  805.  
  806. directory listing program.  Normally these  variables  should  be
  807.  
  808. set  by  the autoexec.bat file.  Below is an example autoexec.bat
  809.  
  810. file:
  811.  
  812.  
  813.         set EDITOR = A:edlin.com
  814.         set IFPDIR = A:sd2.com
  815.  
  816.  
  817.  
  818. _5._4.  _S_t_a_r_t_i_n_g _I_F_P
  819.  
  820.  
  821.      To start an IFP session, change your current working  direc-
  822.  
  823. tory  to a directory on the IFP functions disk.  Then execute the
  824.  
  825. ``ifp.exe'' program.  Your current working directory becomes your
  826.  
  827. current  working  IFP  module.   (There  is no way to change your
  828.  
  829. current working directory from within IFP.  To change  it,  leave
  830.  
  831. the  interpreter and change it within DOS.) When IFP is ready, it
  832.  
  833. will respond with the prompt ``ifp> ''.  To end the IFP  session,
  834.  
  835. enter  the command ``exit''. All function definitions are kept in
  836.  
  837. disk files, so you can't lose anything when you exit or the  com-
  838.  
  839. puter crashes.
  840.  
  841.  
  842.      To edit an IFP definition file, type the command:
  843.  
  844.  
  845.         ed name
  846.  
  847.  
  848. where _n_a_m_e is the name of the function to be edited.  (Since  all
  849.  
  850. IFP  reserved  words are upper case, it is a good practice to use
  851.  
  852. lower or mixed case for function names.) The function may be  one
  853.  
  854. local to the current working module, or one that is imported into
  855.  
  856. the current working module.  If  the  function  name  is  neither
  857.  
  858.                         December 5, 1985
  859.                           IFP Reference                        14
  860.  
  861. defined  locally  nor  imported,  then  it is assumed to be a new
  862.  
  863. local function.  The function definition  file  must  be  of  the
  864.  
  865. form:
  866.  
  867.  
  868.         DEF name AS f;
  869.  
  870.  
  871. Definitions are in  free  format,  line  breaks  are  treated  as
  872.  
  873. spaces.   Matching pairs of ``(*'' and ``*)'' delimit comments as
  874.  
  875. in Pascal.  Note: Do not switch to another file from  within  the
  876.  
  877. editor.   Always  exit  the  editor  to return to the IFP command
  878.  
  879. interpreter first and then edit the next file.  Otherwise  inter-
  880.  
  881. preter  won't  know  that  its  internal  copy  of  a function is
  882.  
  883. invalid.
  884.  
  885.  
  886.      To apply an IFP function, type the command:
  887.  
  888.  
  889.         show object : function;
  890.  
  891.  
  892. The interpreter evaluates the result of applying the function  to
  893.  
  894. the  object.   The result is then pretty-printed at the terminal.
  895.  
  896. Listing 1 shows a sample session.
  897.  
  898.  
  899.      To list your functions, type the command:
  900.  
  901.  
  902.         dir
  903.  
  904.  
  905. The  directory  listing  program  specified  by  IFPDIR  will  be
  906.  
  907. invoked.   _N_o_t_e:  my  directory lister won't work unless I type a
  908.  
  909. trailing slash, i.e. ``dir/".  I have not tried any other  direc-
  910.  
  911. tory listing programs.
  912.  
  913.  
  914.      To delete a function, type the command:
  915.  
  916.  
  917.         del f
  918.  
  919.  
  920. The function definition file (along with the memory copy) will be
  921.  
  922. deleted.   Wildcards  are  not  permitted  in  the function name.
  923.  
  924.                         December 5, 1985
  925.                           IFP Reference                        15
  926.  
  927. _W_a_r_n_i_n_g: do  not  try  to  delete  files  with  extensions  (e.g.
  928.  
  929. ``.bak'')  from  within  IFP, since file names are truncated to 8
  930.  
  931. characters, IFP may delete the wrong file.
  932.  
  933.  
  934. _5._5.  _T_r_a_c_i_n_g _F_u_n_c_t_i_o_n_s
  935.  
  936.  
  937.      Currently, IFP has simple program trace mechanism.  To trace
  938.  
  939. a function, respond to the IFP prompt with:
  940.  
  941.  
  942.         trace on f ,f ,...f ;
  943.                   1  2     n
  944.  
  945. where the f's are functions to  be  traced.   Whenever  a  traced
  946.  
  947. function  is  invoked,  its argument and result are shown.  Also,
  948.  
  949. the argument and result of all called functions  are  shown.   To
  950.  
  951. stop tracing functions, respond to the IFP prompt with:
  952.  
  953.  
  954.         trace off f ,f ,...f ;
  955.                    1  2     n
  956.  
  957.  
  958.      When tracing, the interpreter ellipses are used to  abbrevi-
  959.  
  960. ate  functions.   You  can  set the depth at which ellipses occur
  961.  
  962. with the _d_e_p_t_h command:
  963.  
  964.  
  965.         depth n
  966.  
  967.  
  968. where n is a non-negative integer.  The default depth is two.
  969.  
  970.  
  971.      There is also a functional form  for  creating  trace  func-
  972.  
  973. tions.  Its form is
  974.  
  975.  
  976.         @_s_t_r_i_n_g
  977.  
  978.  
  979. The function formed always returns its argument unchanged, and it
  980.  
  981. prints ``string: '' followed by its argument.  For example,
  982.  
  983.  
  984.         <1 3 5> : EACH @banana END
  985.  
  986.  
  987. will print the messages:
  988.  
  989.  
  990.                         December 5, 1985
  991.                           IFP Reference                        16
  992.  
  993.  
  994.         banana: 1
  995.         banana: 2
  996.         banana: 3
  997.  
  998.  
  999. This tracing functional form is  for  debugging  only,  since  it
  1000.  
  1001. creates a side effect (the message!), it is not truly functional.
  1002.  
  1003.  
  1004.      Program execution can be aborted at  any  time  by  pressing
  1005.  
  1006. control-C.   A  trace  of  where  the function was will be shown.
  1007.  
  1008. Pressing control-C again will abort the trace.
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.                         December 5, 1985
  1057.